//
//  ThreeDetailViewController.m
//  Food
//
//  Created by 15 on 15/7/20.
//  Copyright (c) 2015年 李志远. All rights reserved.
//

#import "ThreeDetailViewController.h"
#import "AFNet.h"
#import "BaseHeader.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKExtension/SSEShareHelper.h>
#import <ShareSDKUI/ShareSDKUI.h>
#import <ShareSDKUI/SSUIShareActionSheetStyle.h>

@interface ThreeDetailViewController ()<MBProgressHUDDelegate>
@property (nonatomic, retain) NSString *httpStr;
@property (nonatomic, retain) NSString *strHttp;
@end

@implementation ThreeDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    Reachability *r = [Reachability reachabilityWithHostName:@"www.baidu.com"];
    if (r.currentReachabilityStatus == NotReachable) {
        UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"提示" message:@"网络连接失败" delegate:self cancelButtonTitle:@"好" otherButtonTitles:nil];
        [alert1 show];
        [alert1 release];
        return;
    }
    [self createProgress];
    [self getData];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-fenxiang"] style:UIBarButtonItemStyleDone target:self action:@selector(share:)];
    // Do any additional setup after loading the view.
    [self.navigationItem.rightBarButtonItem release];
}
- (void)createProgress
{
    self.progress = [[MBProgressHUD alloc] initWithView:self.view];
    self.progress.labelText = @"稍等";
    self.progress.detailsLabelText = @"正在加载...";
    self.progress.delegate = self;
    [self.progress show:YES];
    [self.view addSubview:self.progress];
}

- (void)getData
{

    self.strHttp = [NSString stringWithFormat:@"%@%@", HEAITHKNOWDATAILS, self.IDCode];
    [AFNet connectNetGetDataWithURLString:self.strHttp parameters:nil finishblock:^(id result) {
        Reachability *r = [Reachability reachabilityWithHostName:@"www.baidu.com"];
        if (r.currentReachabilityStatus == NotReachable) {
            UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"提示" message:@"网络连接失败" delegate:self cancelButtonTitle:@"好" otherButtonTitles:nil];
            [alert1 show];
            [alert1 release];
            return;
        }
        self.progress.hidden = YES;
        self.httpStr = [result[@"data"] objectForKey:@"html"];
    [self createWebView];
    }];
}

- (void)createWebView
{
    self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    self.webView.backgroundColor = [UIColor whiteColor];
    [self.webView loadHTMLString:self.httpStr baseURL:[NSURL URLWithString:self.strHttp]];
    [self.view addSubview:self.webView];
    [self.webView release];
}
- (void)share:(UIBarButtonItem *)button
{
    NSLog(@"分享");
#warning 显示内容编辑界面
    //创建分享参数
//    NSLog(@"%@", )
    NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
    [shareParams SSDKSetupShareParamsByText:[NSString stringWithFormat:@"%@ http://www.xiangha.com/zhishi/%@.html",self.titleName, self.IDCode]

                                     images:@[[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.img]]]]
                                        url:nil
                                      title:@"美食坊"
                                       type:SSDKContentTypeImage];



    [ShareSDK showShareEditor:SSDKPlatformTypeSinaWeibo
           otherPlatformTypes:@[@(SSDKPlatformTypeTencentWeibo), @(SSDKPlatformTypeWechat)]
                  shareParams:shareParams
          onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {

              switch (state) {

                  case SSDKResponseStateBegin:
                  {
                      break;
                  }
                  case SSDKResponseStateSuccess:
                  {
                      UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
                                                                          message:nil
                                                                         delegate:nil
                                                                cancelButtonTitle:@"确定"
                                                                otherButtonTitles:nil];
                      [alertView show];
                      break;
                  }
                  case SSDKResponseStateFail:
                  {
                      UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享失败"
                                                                          message:[NSString stringWithFormat:@"%@", error]
                                                                         delegate:nil
                                                                cancelButtonTitle:@"确定"
                                                                otherButtonTitles:nil];
                      [alertView show];
                      break;
                  }
                  case SSDKResponseStateCancel:
                  {
                      UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享已取消"
                                                                          message:nil
                                                                         delegate:nil
                                                                cancelButtonTitle:@"确定"
                                                                otherButtonTitles:nil];
                      [alertView show];
                      break;
                  }
                  default:
                      break;
              }

              if (state != SSDKResponseStateBegin)
              {
              }
              
          }];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
